package logic

import (
	"DataSrv/data"
	"DataSrv/global/model"
	"DataSrv/internal/svc"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassesVideoDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassesVideoDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassesVideoDelLogic {
	return &ClassesVideoDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClassesVideoDelLogic) ClassesVideoDel(in *data.ClassesVideoDelRequest) (*data.ClassesVideoDelResponse, error) {
	// todo: add your logic here and delete this line
	for _, id := range in.VideoIds {
		model.DB.Exec("UPDATE videos SET videos.classes_id = 0 where id = ?", id)
	}
	var video model.Video
	model.DB.Where("videos.classes_id = ?", in.ClassesId).Find(&video)
	if video.ID == 0 {
		model.DB.Where("id = ?", in.ClassesId).Delete(&model.Classes{})
	}
	return &data.ClassesVideoDelResponse{}, nil
}
